/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.icanci.snowstack.config;

import org.springframework.statemachine.annotation.OnTransition;
import org.springframework.statemachine.annotation.WithStateMachine;

/**
 * 事件监听器
 *  - 如果需要处理业务，也可在此进行处理
 * @author icanci
 * @date Created in 2021/05/24 11:26
 * @version 1.0
 */
@WithStateMachine
public class StateMachineEventConfig {
    @OnTransition(source = "UNCONNECTED", target = "CONNECTED")
    public void connect() {
        System.out.println("=====================");
        System.out.println("连接事件, 未连接 -> 已连接");
        System.out.println("=====================\n");
    }

    @OnTransition(source = "CONNECTED", target = "REGISTERING")
    public void register() {
        System.out.println("=====================");
        System.out.println("注册事件, 已连接 -> 注册中");
        System.out.println("=====================\n");
    }

    @OnTransition(source = "REGISTERING", target = "REGISTERED")
    public void registerSuccess() {
        System.out.println("=====================");
        System.out.println("注册成功事件, 注册中 -> 已注册");
        System.out.println("=====================\n");
    }

    @OnTransition(source = "REGISTERED", target = "UNCONNECTED")
    public void unRegister() {
        System.out.println("=====================");
        System.out.println("注销事件, 已注册 -> 未连接");
        System.out.println("=====================\n");
    }
}